<?php
namespace backend\modules\member\controllers;


use backend\component\BackendBaseController;
use backend\service\UserService;
use common\models\member\User;
use backend\service\IdentifyService;
use yii\base\NotSupportedException;

class AuthController extends BackendBaseController
{

    public function actionList() {
        if (\Yii::$app->request->getIsAjax()) {
            return UserService::userAuthListData(\Yii::$app->request->post());
        }
        $model = new User();
        return $this->render("list",["model"=>$model]);
    }


    public function actionView($id) {
        $model = User::modelById($id);
        if ($model->user_type == User::USERTYPE_PERSONAL) {
            $data = IdentifyService::getPersonalData($model->id);
            return $this->render("personal",['data'=>$data,'model'=>$model]);
        } elseif ($model->user_type == User::USERTYPE_COMPANY) {
            $data = IdentifyService::getCompanyData($model->id);
            return $this->render("company",['data'=>$data,'model'=>$model]);
        } elseif ($model->user_type == User::USERTYPE_GROUP) {
            $data = IdentifyService::getGroupData($model->id);
            return $this->render("group",['data'=>$data,'model'=>$model]);
        } else {
            throw new NotSupportedException("不支持的用户身份审核");
        }
    }

    /*
     * 审核用户
     */
    public function actionEdit($id) {
        $model = User::modelById($id);
        return $this->render("edit",["model"=>$model]);
    }


    public function actionModify($id) {
        $post = \Yii::$app->request->post("form");
        return UserService::authUserApply($id,$post);
    }


}